<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>列表</title>
  <script src="https://cdn.bootcss.com/vue/2.6.11/vue.min.js"></script>
  <style>
    .box {
      border-bottom: 1px solid red;
      margin-bottom: 20px;
      padding-bottom: 5px;
    }
    .tip {
      color: red;
    }
  </style>
</head>
<body>
  <h1>v-for</h1>
  <div id="app">
    <div class="box">
      <h3>数组</h3>
      <ul>
        <li v-for="(item, index) in items">
          {{ parentMessage }} - {{ index }} - {{ item.message }}
        </li>
      </ul>
    </div>

    <div class="box">
      <h3>对象</h3>
      <div>
        <ul>
          <li v-for="(value, key, index) in object">
            {{ index }}. {{ key }}: {{ value }}
          </li>
        </ul>
        <button @click="changeo">改变</button>
      </div>
    </div>

    <div class="box">
      <h3>数组检测</h3>
      <p>
        <li v-for="item in list">{{item}}</li>
      </p>
      <button @click="change">改变</button>
    </div>

  </div>

  <script>
    var vue = new Vue({
      el: "#app",
      data: {
        parentMessage: 'Parent',
        items: [
          { message: 'Foo' },
          { message: 'Bar' }
        ],
        object: {
          firstName: 'John',
          lastName: 'Doe',
          age: 30
        },
        list: [0,1,2,3]
      },
      methods: {
        change: function () {
          // this.list[2] = 9
          this.$set(this.list, 2, 9)
        },
        changeo: function () {
          // this.object.sex = 'man'
          this.$set(this.object, 'sex', 'man')
        }
      }
    })
  </script>
</body>
</html>